//
//  OMTViewController.m
//  OMTFlowLayoutLabel
//
//  Created by yizhaorong on 09/08/2018.
//  Copyright (c) 2018 yizhaorong. All rights reserved.
//

#import "OMTViewController.h"
#import <Masonry/Masonry.h>
#import <OMTFlowLayoutLabel/OMTFlowLayoutLabel.h>

@interface OMTViewController ()

//@property (nonatomic, strong) NSMutableArray *datas;

@property (nonatomic, strong) OMTFlowLayoutLabel *flowLayoutLabel;

@end

@implementation OMTViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview:self.flowLayoutLabel];
    self.flowLayoutLabel.maxRow = 5;
    self.flowLayoutLabel.didSelectLabelAtIndexBlock = ^(OMTFlowLayoutLabel *flowLayoutLabel, NSInteger index) {
        NSLog(@"index = %ld", index);
    };
    [self.flowLayoutLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(32);
        make.right.mas_equalTo(-32);
        make.top.mas_equalTo(64);
    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    self.flowLayoutLabel.maxRow = arc4random_uniform(8);
    self.flowLayoutLabel.datas = self.datas;
    [self.flowLayoutLabel reloadData];
}

- (NSMutableArray *)datas {
    NSMutableArray *datas = [NSMutableArray array];
    NSArray *titles = @[@"有志者事竟成有志者事竟成有志者事竟成有志者事竟成有志者事竟成有志者事竟成", @"中华人民共和国", @"标题"];
    for (int i = 1; i <= 10; i++) {
        NSString *title = [NSString stringWithFormat:@"%@ = %i", titles[arc4random_uniform(titles.count)], i];
        [datas addObject:title];
    }
    return datas;
}

- (OMTFlowLayoutLabel *)flowLayoutLabel {
    if (!_flowLayoutLabel) {
        _flowLayoutLabel = [OMTFlowLayoutLabel new];
    }
    return _flowLayoutLabel;
}

@end
